window["DS_COMMON_LOADED"] = true; // flag varible proof common lib has been loaded.

//utility functions,also treat as an common function library.
//xpath helper function
function $x(p, context) {
  if (!context) context = document;
  var i, arr = [], xpr = document.evaluate(p, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  for (i = 0; item = xpr.snapshotItem(i); i++) arr.push(item);
  return arr;
}
//extend object function
function extend(tar,source){
  for(var key in source){
    tar[key] = source[key];
  }
  return tar;
}
//simulate the human click the link
function clickLink(link){
  var randomTime = Math.random()*15000;
  randomTime = randomTime<3000?3000:randomTime;
  var str = "window.location.href = '" + link + "'";
  window.setTimeout(str,randomTime);
}
//function to generate the action probabilty
//probability between 0 - 1
function makeDecision(probability){
  var random = Math.random();
  if(random <= probability) return true;
  return false;
}
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
//getObject by object property from an objects array
Array.prototype.getObjectByProperty = function(property,value){
  for(var i=0;i<this.length;i++){
    if(this[i][property] == value)  return this[i];
  }
  return null;
}
Array.prototype.exists = function(value){
  for(var i=0;i<this.length;i++){
    if(this[i] == value) return i;
  }
  return -1;
}
String.prototype.trim = function(){
  return this.replace(/^\s+|\s+$/g,'');
}